<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>帖子详情</title>

</head>
<body>


<h2>${post.title}</h2>
<p>发布者：${post.userId}</p>
<p>发布日期：${post.createTime}</p>
<p>${post.content}</p>
<c:if test="${post.imageUrl != null}">
    <img src="${pageContext.request.contextPath}${post.imageUrl}" alt="图片" style="max-width: 500px;">
</c:if>
<c:if test="${post.videoUrl != null}">
    <video controls style="max-width: 500px;">
        <source src="${post.videoUrl}" type="video/mp4">
        您的浏览器不支持视频播放。
    </video>
</c:if>
<br>
<a href="${pageContext.request.contextPath}/post/list">返回帖子列表</a>
<!-- 在 post_detail.jsp 中添加评论显示和添加功能 -->
<br>
<h3>评论</h3>
<c:forEach var="comment" items="${comments}">
    <div style="border-top: 1px solid #ccc; padding: 10px;">
        <p>${comment.content}</p>
        <p>评论者：${comment.userId}</p>
        <p>评论时间：${comment.createTime}</p>
    </div>
</c:forEach>
<br>
<form action="${pageContext.request.contextPath}/post/comment" method="post">
    <input type="hidden" name="postId" value="${post.id}">
    <textarea name="content" rows="3" cols="50" placeholder="添加评论..."></textarea>
    <br>
    <button type="submit">提交评论</button>
</form>
<!-- 在 post_detail.jsp 中添加点赞按钮和显示点赞数 -->
<br>
<p>点赞数：${likeCount}</p>
<c:choose>
    <c:when test="${isLiked}">
        <form action="${pageContext.request.contextPath}/post/unlike" method="post">
            <input type="hidden" name="postId" value="${post.id}">
            <input type="hidden" name="userId" value="${user.id}">
            <button type="submit">取消点赞</button>
        </form>
    </c:when>
    <c:otherwise>
        <form action="${pageContext.request.contextPath}/post/like" method="post">
            <input type="hidden" name="postId" value="${post.id}">
            <input type="hidden" name="userId" value="${user.id}">
            <button type="submit">点赞</button>
        </form>
    </c:otherwise>
</c:choose>
<!-- 在 post_detail.jsp 中添加收藏按钮和显示收藏数 -->
<br>
<p>收藏数：${favoriteCount}</p>
<c:choose>
    <c:when test="${isFavorited}">
        <form action="${pageContext.request.contextPath}/post/unfavorite" method="post">
            <input type="hidden" name="postId" value="${post.id}">
            <input type="hidden" name="userId" value="${user.id}">
            <button type="submit">取消收藏</button>
        </form>
    </c:when>
    <c:otherwise>
        <form action="${pageContext.request.contextPath}/post/favorite" method="post">
            <input type="hidden" name="postId" value="${post.id}">
            <input type="hidden" name="userId" value="${user.id}">
            <button type="submit">收藏</button>
        </form>
    </c:otherwise>
</c:choose>
<c:if test="${not empty param.error}">
    <div style="color: red;">${param.error}</div>
</c:if>


</body>
</html>